package com.logic.landseaserver.models.rental.common;

import java.util.HashMap;
import java.util.Map;

import com.logic.landseaserver.common.exception.ResultCode;
import com.logic.landseaserver.common.exception.ResultCodes;

/**
 *
 * 项目名称：system-server</br>
 * 类名称：ResponsResult</br>
 * 类描述：</br>
 * 创建人：Aaron</br>
 * 创建时间：2017年12月13日 上午11:47:58</br>
 * @version 1.0
 *
 */
@SuppressWarnings("rawtypes")
public class ResponsResult extends HashMap implements Map
{
	private static final long serialVersionUID = 7587178577285875735L;

	private static final String RETURNCODE = "returnCode";

	private static final String DESC = "message";

	private static final String DATA = "data";

	private ResultCode resultCode;

	/**
	 * 
	 * 默认是成功，有返回data
	 *    
	 * @param data
	 */
	@SuppressWarnings("unchecked")
	private ResponsResult(Object data)
	{
		resultCode = ResultCodes.SUCCESS;
		put(RETURNCODE, resultCode.getCode());
		put(DESC, resultCode.getDesc());
		put(DATA, data);
	}

	/**
	 * 
	 * 成功返回，有返回data，成功提示自定义
	 *    
	 * @param data
	 * @param successMessage
	 */
	@SuppressWarnings("unchecked")
	private ResponsResult(Object data, String successMessage)
	{
		resultCode = ResultCodes.SUCCESS;
		put(RETURNCODE, resultCode.getCode());
		put(DESC, successMessage);
		put(DATA, data);
	}

	/**
	 * 
	 * 成功返回,无data
	 *    
	 * @param data
	 * @param successMessage
	 */
	@SuppressWarnings("unchecked")
	private ResponsResult()
	{
		resultCode = ResultCodes.SUCCESS;
		put(RETURNCODE, resultCode.getCode());
		put(DESC, resultCode.getDesc());
		put(DATA, "");
	}

	/**
	 * 
	 * 有异常的情况，将异常对象传过来
	 *    
	 * @param resultCode
	 */
	@SuppressWarnings("unchecked")
	private ResponsResult(ResultCode resultCode)
	{
		put(RETURNCODE, resultCode.getCode());
		put(DESC, resultCode.getDesc());
		put(DATA, "");
	}

	public static ResponsResult success()
	{
		ResponsResult responsResult = new ResponsResult();
		return responsResult;
	}

	public static ResponsResult success(Object data)
	{
		ResponsResult responsResult = new ResponsResult(data);
		return responsResult;
	}

	/**
	 * 
	 * [简要描述]：</br>
	 * [详细描述]：</br>
	 * [作者]：Aaron(2017-12-13)</br>
	 *
	 * @param data 返回data
	 * @param successMessage 自定义的成功描述
	 * @return
	 *
	 */
	public static ResponsResult success(Object data, String successMessage)
	{
		ResponsResult responsResult = new ResponsResult(data, successMessage);
		return responsResult;
	}

	/**
	 * 
	 * [简要描述]：</br>
	 * [详细描述]：</br>
	 * [作者]：Aaron(2017-12-13)</br>
	 *
	 * @param resultCode 异常对象
	 * @return
	 *
	 */
	public static ResponsResult exception(ResultCode resultCode)
	{
		ResponsResult responsResult = new ResponsResult(resultCode);
		return responsResult;
	}
	
	/**
	 * 分页塞入查到的list的长度
	 * @param count
	 */
	@SuppressWarnings("unchecked")
	public void setResultTotalCount(Integer count)
	{
		put("TOTAL_COUNT", count);
	}
}

